# 用for...in循环偏历行标，从1到9
for row in range(1, 10):
    # 用for...in循环偏历列标，列从1到行号的循环
    for col in range(1, row + 1):
        # 使用format格式化输出，用:<4占位，
        print('{}*{}={:<4}'.format(row, col, row * col), end=' ')
    # 换行
    print('')
# 输出70个“-”
print('-' * 70)

# 用for...in循环偏历行标，从9到1
for row in range(9, 0, -1):
    # 用for...in循环偏历列标，列从1到行号的循环
    for col in range(1, row + 1):
        # 使用format格式化输出，用:<4占位，
        print('{}*{}={:<4}'.format(row, col, row * col), end=' ')
    # 换行
    print('')
# 输出70个“*”
print('*' * 70)

# 用for...in循环偏历列标，从9到1
for col in range(9, 0, -1):
    # 用for...in循环偏历行标，从1到9
    for row in range(1, 10):
        # 如果列标大于行标
        if col > row:
            # 输出占位8个空字符
            print(' ' * 8, end='')
        # 如果列标小于行标
        else:
            # 用format格式化输出
            print('{}*{}={:>2}'.format(col, row, col * row), end='  ')
    # 换行
    print('')
# 输出70个“-”
print('-' * 70)
# 用for...in循环偏历列标，从1到9
for col in range(1, 10):
    # 用for...in循环偏历行标，从1到9
    for row in range(1, 10):
        # 如果列标大于行标
        if col > row:
            # 输出占位8个空字符
            print(' ' * 8, end='')
        # 如果列标小于行标
        else:
            # 用format格式化输出
            print('{}*{}={:>2}'.format(col, row, col * row), end='  ')
    # 换行
    print('')
# 输出70个“*”
print('*' * 70)

row = 1
while row < 10:
    col = 1
    while col < row + 1:
        print("{}*{}={:>2}".format(col, row, row * col), end="  ")
        col += 1
    row += 1
    print('')

print('-' * 70)

row = 9
while row > 0:
    col = 1
    while col < row + 1:
        print("{}*{}={:>2}".format(col, row, row * col), end="  ")
        col += 1
    row -= 1
    print('')

print('*' * 70)

row = 9
while row > 0:
    col = 1
    while col < 10:
        if row > col:
            print(" " * 8, end="")
        else:
            print("{}*{}={:>2}".format(row, col, row * col), end="  ")
        col += 1
    row -= 1
    print('')

print('-'*70)

row = 1
while row < 10:
    rol = 1
    while rol < 10:
        if row > rol:
            print(" " * 8, end="")
        else:
            print("{}*{}={:>2}".format(row, rol, row * rol), end="  ")
        rol += 1
    row += 1
    print()
